package com.molyfun.parents.fragment.dialog;

import android.os.Bundle;
import android.support.v4.app.DialogFragment;
import android.support.v4.app.FragmentTransaction;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.molyfun.parents.R;
import com.molyfun.parents.rest.bean.GetReportResultResponse;

import butterknife.ButterKnife;
import butterknife.InjectView;

public class EvaluateAnalyzeTableDialogFragment extends DialogFragment implements View.OnClickListener{

    @InjectView(R.id.title)
    TextView mTitle;
    @InjectView(R.id.table_abilitystatus)
    TextView mAbilityStatus;
    @InjectView(R.id.table_analyze)
    TextView mAnalyze;
    @InjectView(R.id.table_suggestion_layout)
    LinearLayout mSuggestionLayout;
    @InjectView(R.id.month_start)
    TextView mMonthStart;
    @InjectView(R.id.month_end)
    TextView mMonthEnd;

    GetReportResultResponse.ReportDetailTableCell projectlistBean;

    private static EvaluateAnalyzeTableDialogFragment newInstance(GetReportResultResponse.ReportDetailTableCell projectlistBean) {
        EvaluateAnalyzeTableDialogFragment evaluateAnalyzeTableDialogFragment = new EvaluateAnalyzeTableDialogFragment();
        Bundle bundle = new Bundle();
        bundle.putParcelable("project_list_bean", projectlistBean);
        evaluateAnalyzeTableDialogFragment.setArguments(bundle);
        return evaluateAnalyzeTableDialogFragment;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        getDialog().requestWindowFeature(Window.FEATURE_NO_TITLE);
        View view = inflater.inflate(R.layout.dialog_evaluate_analyze, container, false);
        view.findViewById(R.id.close).setOnClickListener(this);
        ButterKnife.inject(this, view);

        projectlistBean = getArguments().getParcelable("project_list_bean");
        if(projectlistBean != null){
            mTitle.setText(projectlistBean.getCategory());
            mAbilityStatus.setText( projectlistBean.getAbilitystatus());
            mAnalyze.setText(projectlistBean.getAdanalysis());
            mMonthStart.setText(projectlistBean.getBeginvalue() + "月");
            mMonthEnd.setText(projectlistBean.getEndvalue() + "月");

            if(projectlistBean.getEdusuggestionlist() != null && projectlistBean.getEdusuggestionlist().size() > 0){
                for(GetReportResultResponse.EduSuggestionBean eduSuggestionBean : projectlistBean.getEdusuggestionlist()){
                    View tableCellLayout = LayoutInflater.from(getContext()).inflate(R.layout.view_evaluate_analyze_table_cell, null, false);
                    ((TextView)tableCellLayout.findViewById(R.id.evaluate_table_cell_title)).setText(eduSuggestionBean.getAgeRange());
                    ((TextView)tableCellLayout.findViewById(R.id.evaluate_table_cell_content)).setText(eduSuggestionBean.getContent());
                    mSuggestionLayout.addView(tableCellLayout);
                }
            }
        }

        return view;
    }


    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.close:
                break;
            default:
                break;
        }
        getDialog().dismiss();
    }

    public static class EvaluateAnalyzeTableDialogBuilder {

        EvaluateAnalyzeTableDialogFragment mCourseContentDialogFragment;
        private String mTag;

        public EvaluateAnalyzeTableDialogBuilder(GetReportResultResponse.ReportDetailTableCell projectlistBean){
            mCourseContentDialogFragment = EvaluateAnalyzeTableDialogFragment.newInstance(projectlistBean);
            mTag = "evaluate_analyze_table";
        }

        public EvaluateAnalyzeTableDialogBuilder setTag(String tag){
            this.mTag = tag;
            return this;
        }

        public void build(FragmentTransaction fragmentTransaction){
            fragmentTransaction.add(mCourseContentDialogFragment, mTag);
            fragmentTransaction.commitAllowingStateLoss();
        }

    }
}
